﻿@{
    ViewBag.Title = "";
    var id = Model != null ? Model.ID : 0;
}
@using ZBJF.Warranty.BLL
@using ZBJF.Warranty.WebProvider
@model ZBJF.Warranty.Model.SortingCenter
<ul class="nav nav-tabs">
    <li><a href="/SortingCenter/SortingCenterIndex">分拣中心列表</a></li>
    <li class="active"><a href="/SortingCenter/SortingCenterEdit/@id">@(id > 0 ? "编辑分拣中心" : "添加分拣中心")</a></li>
</ul>
@using (Html.BeginForm("SaveSortingCenter", "SortingCenter", FormMethod.Post, new { id = "mvcForm", name = "mvcForm", @class = "form-horizontal", enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()
    @Html.HiddenFor(c => c.ID)
    <div class="control-group">
        <label class="control-label">分拣中心名称：</label>
        <div class="controls">
            @Html.TextBoxFor(m => m.SortingCenterName, new { validate = "{required:true,messages:{required:'请输入分拣中心名称'}}", maxLength = 20 })
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">所在省：</label>
        <div class="controls">
            @Html.DropDownListFor(m => m.ProvinceId, ConvertToSelector.Instance.D_ProvinceConvertToSelectList(), new { validate = "{required:true,messages:{required:'请选择省份'}}" })
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">所在市：</label>
        <div class="controls">
            @Html.DropDownListFor(m => m.CityId, ConvertToSelector.Instance.D_CityConvertToSelectList(Model == null ? 0 : Model.ProvinceId), new { validate = "{required:true,messages:{required:'请选择城市'}}" })
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">详细地址：</label>
        <div class="controls">
            @Html.TextBoxFor(m => m.Address, new { validate = "{required:true,messages:{required:'请输入详细地址'}}", maxLength = 100 })
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">联系电话：</label>
        <div class="controls">
            @Html.TextBoxFor(m => m.ContactPhone, new { validate = "{required:true,messages:{required:'请输入联系电话'}}", maxLength = 15 })
        </div>
    </div>
    <div class="control-group">
        <label class="control-label"></label>
        <div class="controls">
            <label>
                @Html.CheckBoxFor(m => m.IsAvailable)
                是否可用
            </label>
        </div>
    </div>
    <div class="form-actions">
        <input id="btnSubmit" class="btn btn-primary Edit-R" type="button" value="保存" onclick="loading(this)">
        <input id="btnCancel" class="btn" type="button" value="重置" onclick="reset()">
    </div>
}
@section scripts{
    <script>
        $(function () {
            //设备类型选择事件
            $("#ProvinceId").on("change", function () {
                var _value = $(this).val();
                if (!_value)
                {
                    $("#CityId").html("<option value>请选择</option>");
                    return;
                }
                //设置配件类型
                setSelectData("/Common/GetCityList", "GET", "CityId", { provinceID: _value }, "Value", "Text", true);
            })

        })
        function reset() {
            document.getElementById("mvcForm").reset();
        }
        function loading(_this) {
            if ($("#mvcForm").valid()) {
                _this.disabled = 'disabled';
                document.getElementById("mvcForm").submit();
            }
        }

        //数据后台地址 | 请求方式（post/get） | select标签的ID | 请求参数 | Value对应的字段名称 | Text对应的字段名称 | 是否有默认选项 true/false
        function setSelectData(url, postType, selectId, params, valueName, textName, hasDefault) {
            //加载所有的带接入列表
            $.ajax({
                type: postType,
                url: url,
                dataType: "json",
                data: params,
                success: function (data) {
                    var _data = data;
                    var _html = "";
                    if (hasDefault == true) {
                        _html += "<option value=''>请选择</option>";
                    }
                    if (_data && _data.length > 0) {
                        _data.forEach(function (item) {
                            _html += "<option value='" + item[valueName] + "'>" + item[textName] + "</option>";
                        })
                    }
                    $("#" + selectId).html(_html);
                }
            });
        }
    </script>
}